//
//  Person.m
//  OC_07_内存管理
//
//  Created by wyx on 16/3/4.
//  Copyright © 2016年 Apon. All rights reserved.
//

#import "Person.h"

@implementation Person
/** 实现了 setter,getter 方法在 Xcode4后版本之后,此行省略
  注意:但是入股同时重写
 */

@synthesize gen = _gen;
@synthesize age = _age;
@synthesize name = _name;

#pragma mark - Creating and Init Person
- (instancetype)initWithName:(NSString *)name age:(NSString *)age gen:(NSString *)gen{
    self = [super init];
    if (self) {
        self.name = name;
        self.age = age;
        self.gen = gen;
    }
    return self;
}
+ (instancetype)personWithName:(NSString *)name age:(NSString *)age gen:(NSString *)gen{
    return [[[Person alloc] initWithName:name age:age gen:gen] autorelease];
}
#pragma mark - overwrite
//重写 dealloc方法
-(void)dealloc{
    NSLog(@"person 对象马上就清空了");
    [super dealloc];//最后一句必须调用父类的 dealloc 方法 完成内存释放
}
#pragma mark - 实现Copying协议方法
- (id)copyWithZone:(NSZone *)zone{
    //实现对象的拷贝
    Person *person = [[Person allocWithZone:zone] init];
    person.name = self.name;
    person.age = self.age;
    person.gen = self.gen;
    return person;
}
#pragma mark - setter getter
/** retain 语义设置的属性 setter 方法实现 */
- (void)setSex:(NSString *)gen{
    if (_gen != gen) {
        [_gen release];
        _gen = [gen retain];
    }
}
- (NSString *)gen {
    return [[_gen retain] autorelease];
}
/** assgin 语义设置属性 setter getter方法实现 */
- (void)setAge:(NSString *)age{
    if (_age != age) {
        [_age release];
        _age = [age retain];
    }
}
- (NSString *)age {
    return [[_age retain] autorelease];
}
/** copy 语义设置属性 */
- (void)setName:(NSString *)name{
    if (_name != name) {
        [_name release];
        _name = [name copy];
    }
}
- (NSString *)name {
    return [[_name retain] autorelease];
}

@end
